/**
 * Copyright (c) 2009  Collaborative Development Group, C.S. Dept., University of Bari
 *
 * All rights reserved. This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0  which accompanies this distribution, and is 
 * available at http://www.eclipse.org/legal/epl-v10.html
 */
package it.uniba.di.cdg.penelope.ui;

import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;

/**
 * Wrapper for some of the common Eclipse singletons like the default {@link IWorkbench} or {@link Display} instances.
 * <br/>
 * Clients should install or inherit this module in order to gain such references. 
 */
public class EclipseSupportConfig extends AbstractModule {

	/* (non-Javadoc)
	 * @see com.google.inject.AbstractModule#configure()
	 */
	@Override
	protected void configure() {
		// Nothing: just export the providers.
	}

	/**
	 * Eclipse Exporters.
	 * @return the current {@link Display} instance, if available
	 */
	@Provides
	protected Display getDisplay() {
    	Display display = PlatformUI.getWorkbench().getDisplay();
        if (display == null) { // Fallback
            display = Display.getCurrent();
        }
        return display;		
	}

	/**
	 * Provides the default workbench to this configuration.
	 * @return the default workbench
	 */
	@Provides
	protected IWorkbench getWorkbench() {
		return PlatformUI.getWorkbench();
	}

}
